home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / WTEK0593.ZIP;1 / PALETTE.ZIP / NOPAL.C < prev   
Encoding:
C/C++ Source or Header  |  1993-04-09  |  3.8 KB  |  110 lines

  1. #include <windows.h>
  2.  
  3. long FAR PASCAL WndProc (HWND hWnd, WORD iMessage, WORD wParam, LONG lParam);
  4. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
  5. {
  6.     static HWND hWnd;
  7.     MSG Message;
  8.     WNDCLASS WndClass;
  9.  
  10.     if (!hPrevInstance)
  11.     {
  12.         WndClass.cbClsExtra = 0;
  13.         WndClass.cbWndExtra = 0;
  14.         WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  15.         WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  16.         WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  17.         WndClass.hInstance = hInstance;
  18.         WndClass.lpfnWndProc = (WNDPROC)WndProc;
  19.         WndClass.lpszClassName = "NOPAL";
  20.         WndClass.lpszMenuName = NULL;
  21.         WndClass.style = CS_HREDRAW | CS_VREDRAW;
  22.     
  23.         RegisterClass (&WndClass);
  24.     }
  25.  
  26.     hWnd = CreateWindow ("NOPAL", "Color Example 1: NoPal",
  27.         WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
  28.         0, CW_USEDEFAULT, 0, NULL, NULL,
  29.         hInstance, NULL);
  30.  
  31.     ShowWindow (hWnd, nCmdShow);
  32.     while (GetMessage (&Message, 0, 0, 0))
  33.     {
  34.         TranslateMessage(&Message);
  35.         DispatchMessage(&Message);
  36.     }
  37.     return Message.wParam;
  38. }
  39.  
  40. /************************************************/
  41. /*          Window Procedure :  WndProc         */
  42. /************************************************/
  43. long FAR PASCAL WndProc (HWND hWnd, WORD iMessage, WORD wParam, LONG lParam)
  44. {
  45.  
  46.     /**** Device Context variables ****/
  47.     HDC hDC;
  48.  
  49.     /**** Pens and brushes ****/
  50.     LOGPEN lpBlue;                                                  // Logical outline pen.
  51.     LOGBRUSH lbBlue;                                                // Logical fill brush.
  52.     static HPEN hBluePen, hOldPen;          // Actual new and previous pens.
  53.     static HBRUSH hBlueBrush, hOldBrush;            // Actual new and previous brushes.
  54.     PAINTSTRUCT PtStr;                                              // Something used by the Begin/EndPaint routines.
  55.  
  56.     /**** General variables ****/
  57.     short x;                                                                // Generic counter for loops.
  58.     int curcolor;                           // Current color.
  59.  
  60.     switch (iMessage)
  61.     {
  62.         case WM_PAINT:
  63.             lpBlue.lopnStyle = PS_SOLID;
  64.             lpBlue.lopnWidth.x = 1;
  65.             lpBlue.lopnWidth.y = 0;         // Not used
  66.  
  67.             lbBlue.lbStyle = BS_SOLID;
  68.             lbBlue.lbHatch = 0;                     // Ignored when BS_SOLID
  69.                                  
  70.             hDC = BeginPaint(hWnd, &PtStr);
  71.             curcolor = 0;
  72.             for (x=1, curcolor=0; x<640; x=x+16, curcolor = curcolor + 6)
  73.             {
  74.                 //*** Reference our colors:
  75.                   lpBlue.lopnColor = RGB(0,0,curcolor);
  76.                   lbBlue.lbColor = RGB(0,0,curcolor);
  77.  
  78.                 //*** Create outline pen and fill brush:
  79.                   hBluePen = CreatePenIndirect(&lpBlue);
  80.                   hBlueBrush = CreateBrushIndirect(&lbBlue);
  81.  
  82.                 //*** Tell hDC to use new pen&brush:
  83.                   hOldPen = SelectObject (hDC, hBluePen);
  84.                   hOldBrush = SelectObject (hDC, hBlueBrush);
  85.  
  86.                 //*** Draw a cute picture:
  87.                   RoundRect (hDC,x,100,x+16,200,10,10);
  88.  
  89.  
  90.  
  91.                 //*** De-allocate the current pen and brush.
  92.                   SelectObject (hDC, hOldPen);
  93.                   SelectObject (hDC, hOldBrush);
  94.                   DeleteObject(hBluePen);
  95.                   DeleteObject(hBlueBrush);
  96.             }
  97.  
  98.         EndPaint(hWnd, &PtStr);         // Tell GDI we're done with device context.
  99.         return (0);
  100.  
  101.     case WM_DESTROY:
  102.         PostQuitMessage(0);
  103.         return (0);
  104.     default:
  105.         return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  106.     }
  107. }
  108.  
  109.  
  110.